// lib/dashboard.ts
import { apiClient } from './apiClient'
// 定义数组中每个对象的类型
interface StatDataItem {
    name: string;       // X轴标签（如"周一"、"产品A"）
    value: number;      // 访问量（数值）
    percentage: number; // 完成率（百分比数值）
}
export type DashboardItem = {
    id: string;
    name: string;
    type: string;
    module: string;
    description: string;
    status: 'active' | 'inactive';
    createTime: string;
    updateTime: string;
    creator: string;
    stateData: StatDataItem[]
}

export async function fetchDashboardItems({
    page = 1,
    pageSize = 3,
}: {
    page?: number
    pageSize?: number
}): Promise<DashboardItem[]> {
    const res = await apiClient.post<{ data: DashboardItem[] }>(
        '/api/dashboard',
        { page, pageSize }
    )
    return res.data
}

export async function fetchDashboardItem({
    id
}: {
    id: string
}): Promise<DashboardItem> {
    const res = await apiClient.get<{ data: DashboardItem }>(
        `/api/card/${id}`
    )
    return res.data
}
